#include <QFileDialog>
#include "tsdataimport.h"

TSDataImport::TSDataImport(QWidget *parent) : QDialog(parent)
{
	ui.setupUi(this);
}

void TSDataImport::on_cmdAddFiles_clicked()
{
	QStringList fileNames = QFileDialog::getOpenFileNames(
			this,
			tr("Import Time Series Data Set"),
			QDir::current().absolutePath(),
			tr("All Files (*.*);;Data files (*.dat)")
	);
	for ( int i = 0; i < fileNames.size(); ++i) {
		ui.listFiles->addItem(fileNames.at(i));
	}
	if ( ui.listFiles->count() > 0 ) {
		ui.cmdOK->setEnabled(true);
		ui.cmdRemove->setEnabled(true);
	} else {
		ui.cmdOK->setEnabled(false);
		ui.cmdRemove->setEnabled(false);
	}
}

void TSDataImport::on_cmdRemove_clicked()
{
	ui.listFiles->takeItem ( ui.listFiles->currentRow() );
	if ( ui.listFiles->count() > 0 ) {
		ui.cmdOK->setEnabled(true);
		ui.cmdRemove->setEnabled(true);
	} else {
		ui.cmdOK->setEnabled(false);
		ui.cmdRemove->setEnabled(false);
	}
}

void TSDataImport::on_cmdOK_clicked()
{
	this->close();
}

void TSDataImport::on_cmdCancel_clicked()
{
	this->close();
	ui.listFiles->clear();
}

QStringList TSDataImport::getFiles ()
{
	QStringList result;
	for (int i = 0; i < ui.listFiles->count(); ++i) {
		result.push_back ( ui.listFiles->item(i)->text() );
	}
	return result;
}

TSData::TSDataType TSDataImport::getDataType()
{
	if ( ui.radioDouble->isChecked() ) {
		return TSData::DoubleColumn;
	} else if (ui.radioSingle->isChecked() ) {
		return TSData::SingleColumn;
	} else {
		return TSData::DoubleColumn;
	}
}

TSDataImport::~TSDataImport()
{
	// Do nothing
}
